#pragma once

#include <winsock2.h>
#include <boost/type_traits.hpp>

namespace	Z	{

//------------------------------------------------------------------------------------------------------------------------
inline	void	closeHandle(HANDLE& h)	{
	if(h != 0)	{
		::CloseHandle(h);
		h	= 0;
	}
}

inline	void	closeSocket(SOCKET& so)	{
	if(so != INVALID_SOCKET)	{
		::closesocket(so);
		so	= INVALID_SOCKET;
	}
}

inline	void	closeEvent(WSAEVENT& e)	{
	if(e != 0)	{
		::WSACloseEvent(e);
		e	= 0;
	}
}

template<typename T>
inline	void	deletePtr(T*& ptr)	{
	if(ptr != nullptr)	{
		delete ptr;
		ptr	= nullptr;
	}
}

template<typename T>
inline	void	zeroise(T& t)	{
	BOOST_STATIC_ASSERT(!(boost::is_pointer<T>::value || boost::is_polymorphic<T>::value));
	::memset(&t, 0, sizeof(t));
}

struct	SystemInfo
	:	public	SYSTEM_INFO
{
	SystemInfo()	{
		::GetSystemInfo(this);
	}
};

}